package com.ktty.test;

import com.ktty.entity.SysUser;
import com.ktty.service.SysUserService;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

public class Main {
    Logger logger = LoggerFactory.getLogger(Main.class);

    @Test
    public void test(){
        //1.获取spring的上下文对象
        ApplicationContext context=new
                ClassPathXmlApplicationContext("applicationContext.xml");
        //2.获取对象
        SysUserService userService = (SysUserService) context.getBean("sysUserService");
        // 构建查询条件
        SysUser queryCondition = new SysUser();
        queryCondition.setRealName("李");
        queryCondition.setRoleId(3);
        List<SysUser> userList = userService.getUserList(queryCondition);
        // 循环输出查询到的用户信息
        for (SysUser user : userList) {
            logger.info("SysUser: account={}, realName={}, roleName={}",
                    user.getAccount(), user.getRealName(),
                    user.getSysRole().getRoleName());
        }
    }

    @Test
    public void test2(){
        //1.获取spring的上下文对象
        ApplicationContext context=new
                ClassPathXmlApplicationContext("applicationContext.xml");
        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                "applicationContext-dao.xml",
                "applicationContext-service.xml");
        //2.获取对象
        SysUserService sysUserService = (SysUserService) context.getBean("sysUserService");

        SysUser user1 = new SysUser();
        user1.setAccount("ceshi1");
        user1.setRealName("测试用户1");

        SysUser user2 = new SysUser();
        user2.setAccount("ceshi2");
        user2.setRealName("测试用户2");

        List<SysUser> userList = Arrays.asList(user1, user2);
        // 测试保存数据
        sysUserService.saveBatch(userList);
    }
}
